package com.slz3.business.module.orderManagement.ordOrderLine.domain;

import com.slz3.business.frame.enums.AuditFlag;
import com.slz3.business.frame.enums.UsingFlag;
import com.slz3.business.frame.util.UUIDUtils;
import com.slz3.business.frame.util.VE;

import java.time.LocalDateTime;
import java.util.Optional;
import java.util.UUID;

public class OrdOrderLineFactory {

    /**
     * 初始化基础属性值
     */
    public static OrdOrderLine initBaseFields(OrdOrderLine ordOrderLine) {
        if (ordOrderLine.getUuid() == null) {
            ordOrderLine.setUuid(UUIDUtils.generateUUID());
            ordOrderLine.setCreateTime(LocalDateTime.now());
            if (VE.isEmpty(ordOrderLine.getSerAudit())) {
                ordOrderLine.setSerAudit(AuditFlag.WAIT_SUBMIT);
            }
            if (VE.isEmpty(ordOrderLine.getSerUsing())) {
                ordOrderLine.setSerUsing(UsingFlag.ENABLE);
            }
        } else {
            ordOrderLine.setLastModifyTime(LocalDateTime.now());
        }
        return ordOrderLine;
    }

    /**
     * 初始化基础属性值
     */
    public static OrdOrderLine initBaseFields() {
        return initBaseFields(newTemStyle());
    }

    public static OrdOrderLine newTemStyle() {
        return new OrdOrderLine();
    }

    public static OrdOrderLine newByOrderDetail(OrderDetail orderDetail){
        OrdOrderLine ordOrderLine = new OrdOrderLine();
        ordOrderLine.setUuid(UUID.fromString(orderDetail.getUuid()));
        if(VE.isNotEmpty(orderDetail.getSerOrderPrice()))
            ordOrderLine.setSerOrderPrice(Double.valueOf(orderDetail.getSerOrderPrice()));
        ordOrderLine.setSerItemName(Optional.ofNullable(orderDetail.getSerItemName()).orElse(""));
        ordOrderLine.setSerItemId(UUID.fromString(orderDetail.getSerItemId()));
        ordOrderLine.setSerItemNum(Optional.ofNullable(orderDetail.getSerItemNum()).orElse(""));
        ordOrderLine.setSerItemImg(Optional.ofNullable(orderDetail.getSerGoodsImgUrl()).orElse(""));
        ordOrderLine.setSerOrderCount(Integer.valueOf(orderDetail.getSerOrderCount()));
        ordOrderLine.setSerOrderId(UUID.fromString(orderDetail.getSerOrderUuid()));
        ordOrderLine.setSerOrderNumber(orderDetail.getSerOrderNumber());
        ordOrderLine.setSerMemo(orderDetail.getSerMemo());
        switch (orderDetail.getSerOrderType()){
            case "1":
                ordOrderLine.setSerOrderType(OrderyTypeEnum.JIFENGOODS);
                break;
            case "2":
                ordOrderLine.setSerOrderType(OrderyTypeEnum.GOODS);
                break;
            case "3":
                ordOrderLine.setSerOrderType(OrderyTypeEnum.CHOUJIANGGOODS);
                break;
            default:
                ordOrderLine.setSerOrderType(null);
                break;
        }
        return ordOrderLine;
    }

}
